/**
 *
 * author ThuanLT
 * Aug 20, 2014 10:29:40 PM
 *
 */
package vn.fsoft.gst.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import vn.fsoft.gst.domain.County;

@Repository
public class CountyDAOImpl implements CountyDAO{

	@Autowired
	private SessionFactory sessionFactory;
	@Transactional
	public int addCounty(County county) {
		return (Integer) sessionFactory.getCurrentSession().save(county);
		
	}
	@Transactional
	public void updateCounty(County newCounty) {
		sessionFactory.getCurrentSession().merge(newCounty);
	}
	@Transactional
	public void deleteCounty(int countyID) {
		County c = getCountyByID(countyID);
		sessionFactory.getCurrentSession().delete(c);
	}
	@SuppressWarnings("unchecked")
	@Transactional
	public List<County> getListCounty() {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(County.class);
		return criteria.list();
	}
	@Transactional
	public County getCountyByID(int countyID) {
		return (County) sessionFactory.getCurrentSession().get(County.class, countyID);
	}
	
}
